Doomsday

The Doomsday algorithm #
There is a fairly easy way to mentally calculate the weekday for any given date. The mathematician John Conway came up with the Doomsday rule, based on the observation that certain dates within a year such as 4/4, 6/6, 8/8, 10/10 and 12/12 all fall on the same day of the week.
The easiest method is to combine a simple calculation with memorising a few numbers for the 12 months:
Month | Code |
---|---|
January | 6 |
February | 2 |
March | 2 |
April | 5 |
May | 0 |
June | 3 |
July | 5 |
August | 1 |
September | 4 |
October | 6 |
November | 2 |
December | 4 |
As an example we will use 21 July 1969, the day that Neil Armstrong set foot on the moon. After our first example, we will see how we can simplify the calculations.
First, we need to calculate a number for the year. The first step is the take the last two digits of the year. Divide by 4 and round down, and then add the result to the year number.
For 1969, we divide 69 by 4 and round down to get 17. Adding this to 69, we have 69 + 17 equals 86.
The second step of the year number is to add the century number:
Century | Number |
---|---|
1700 | 5 |
1800 | 3 |
1900 | 1 |
2000 | 0 |
This table repeats, so for 2100 we use 5, for 2200 add 3, and so on.
For 1969 we add 1 (for 1900) to our result to get 86 + 1 equals 87.
The final step of the year number is to subtract 1 from our total if our date is in January or February of a leap year.
1969 is not a leap year, so we keep 87 as our final year code.
Now that we have our year code, we add the month code from the table.
The code for July is 5, so we get 87 + 5 equals 92.
Finally, we just add the day of the month to our total.
For the 21st of July we add 92 + 21 equals 113.
Now we need the remainder of this total after division by 7. This final result gives us our weekday.
Result | Weekday |
---|---|
0 | Sunday |
1 | Monday |
2 | Tuesday |
3 | Wednesday |
4 | Thursday |
5 | Friday |
6 | Saturday |
The remainder of 113 / 7 is 1, which give us Monday.
Now that we know how to calculate the weekday, we can do some simplifications. Since we only need the end result modulo 7 (i.e. we need the remainder after division by 7), we can also reduce our intermediate results modulo 7.
Note that we cannot reduce the year number before division by 4, but all other values can be taken mod 7.
Using the same example, 69 / 4 equals 17 (rounding down). We can take this modulo 7 by subtracting 14, resulting in 3. The value 69 itself is 6 mod 7 (or -1, since it’s 70 - 1), so for the year we have 3 + 6 equals 9, or 2 (mod 7).
Add 1 for the century (1900) and 5 for the month, resulting in 2 + 1 + 5 equals 8, or 1 (mod 7). For the date we have 21, which is a multiple of 7, so it’s 0 (mod 7). Now just add 0 to 1, and we have 1 for our weekday number, corresponding to Monday.
For another example, let’s try 1 February 2020. Starting with the year we have 20 / 4 equals 5. Add this to 20 to get 25, or 4 if we simplify modulo 7. We do not need to add a century number (since that’s 0 for 2000), but our date is in January or February of a leap year, so we do need to subtract 1 from our 4, resulting in 3.
Note that if our intermediate result would have been 0, we would get 0 - 1 equals -1, but modulo 7 we could replace this by 6.
For February we add 2, and for the day of the month 1, so 3 + 2 + 1 equals 6, which corresponds to Saturday.
In case you didn’t know, a year is a leap year if it is a multiple of 4, unless it is a multiple of 100, unless it is a multiple of 400. So 1700, 1800 and 1900 were not leap years, but 2000 was a leap year.
There is a clever alternative for the first steps of the year calculation. Instead of adding the year divided by 4 to the year itself, we can use the ‘odd 11’ method:
- start with the last two digits of the year
- if it’s odd, add 11
- divide by 2
- if it’s odd, add 11
- subtract the result modulo 7 from 7
After that, don’t forget to add the century number and subtract 1 if necessary for January or February in a leap year.
Going back to 1969 where we ended up with 86 or 2 (mod 7), the odd 11 method gives:
- 69 is odd, so add 11 to get 80
- divide by 2 to get 40
- 40 is even, so do not add 11
- 40 is 5 (mod 7), so we get 7 - 5 equals 2
For 2020 we got 25 or 4 earlier. Using odd 11:
- 20 is even, so do not add 11
- divide by 2 to get 10
- 10 is even, so do not add 11
- 10 equals 3 (mod 7), so we get 7 - 3 equals 4
Finally, if you are using a memory system like PAO, you could skip the year calculation by memorising the 100 values. The easiest way is to create 7 rooms for the results 0 to 6, and put all persons in the corresponding room. So your person for 69 should go in the 2-room, and your person for 20 in the 4-room.